The field of the present invention pertains to lighting polygon services in three dimensional computer graphics. More particularly, the present invention relates to a method and system for efficiently computing two sided vertex lighting in a three dimensional computer graphics rendering system.
Computer graphics are being used today to perform a wide variety of tasks. Many different areas of business, industry, government, education, entertainment, and most recently, the home, are tapping into the enormous and rapidly growing list of applications developed for today""s increasingly powerful computer devices.
Graphics have also become a key technology for communicating ideas, data, and trends in most areas of commerce, science, and education. Modern graphics workstations often implement real time user interaction with three dimensional (3D) models and pseudo-realistic images. These workstations typically contain dedicated, special purpose graphics hardware. The progress of semiconductor fabrication technology has made it possible to do real time 3D animation, with color shaded images of complex objects, described by thousands of polygons, on powerful dedicated rendering subsystems. The most recent and most powerful workstations are capable of rendering completely life-like, realistically lighted, 3D objects and structures.
In a typical 3D computer generated object, the surfaces of the 3D object are described by data models. These data models store xe2x80x9cprimitivesxe2x80x9d (usually mathematically described polygons and polyhedra) that define the shape of the object, the object attributes, and the connectivity and positioning data describing how the objects fit together. The component polygons and polyhedra connect at common edges defined in terms of common vertices and enclosed volumes. The polygons are textured, Z-buffered, and shaded onto an array of pixels, creating a realistic 3D image.
In a typical graphics computer, most of the actual rendering computation is performed by a graphics subsystem included in the graphics computer. The 3D object data models are xe2x80x9ctraversedxe2x80x9d by a software program (e.g., in response to user input) running on one or more processors in a processor subsystem within the graphics computer. The primitives describing the 3D object are processed by the processor subsystem and sent to the graphics subsystem for rendering. For example, a 3D polyhedra model of an object is sent to the graphics subsystem as contiguous strips of polygons, sent to the graphics subsystem as a graphics data stream (e.g., primitives, rendering commands, instructions, etc.). This graphics data stream provides the graphics subsystem with all the information required to render the 3D object and the resulting scene. Such information includes, for example, specular highlighting, anti-aliasing, depth, transparency, and the like. Using this information, the graphics subsystem performs all the computational processing required to realistically render the 3D object. The hardware of the graphics subsystem is specially tuned to perform such processing quickly and efficiently in comparison to the processor subsystem.
Lighting and the realistic rendering of lighting effects is becoming an increasingly important part of the 3D rendering process. In order to portray a more realistic real-world representation, lighting effects (e.g., specular highlights, reflections, shadows, etc.) are usually applied to the 3D objects of the scene during rendering. The term xe2x80x9clightingxe2x80x9d often refers to the application of specular highlights after texturing for generating more realistic lighting effects within the resulting image. Other lighting techniques are also used, such as, for example, using multi-texturing with two-dimensional (2D) texture images, or texture maps, after the initial texturing. For example, given a featureless solid cube and a texture map defining a wood grain pattern, texture mapping techniques may be used to map the wood grain pattern onto the cube and lighting techniques can be used to realistically color the surface of the cube in accordance with the 3D environment of the image. The resulting is that of a cube that appears to be made of wood having realistic specular highlights in accordance with light sources (e.g., ambient lights, spotlights, diffuse light, etc.) within the scene.
There exists a problem however, with regard to lighting successive polygons in an environment where the geometry of the successive polygons change with respect to the viewing point. A significant portion of rendering computation for the 3D image involves computing realistic lighting effects from the one or more light sources within the 3D scene. Accordingly, it is very desirable for the lighting operations within the 3D pipeline to proceed as efficiently as possible. Conventional 3D graphics pipelines are currently set up to compute lighting of successive polygons based upon the polygons being viewed from a common direction, or viewpoint. The geometry of the polygons with respect to the view point may position one or more polygons such that the xe2x80x9cback-sidexe2x80x9d is being viewed as opposed to the xe2x80x9cfront-sidexe2x80x9d as with the preceding polygons. This necessitates the graphics pipeline computing the back-side color for these polygons as opposed to the front-side color for the preceding polygons. Due to the nature of the graphics pipeline, this causes a stall, wherein queued data (e.g., color information from preceding vertices of preceding polygons) needs to be discarded and new data for the back-side color of the preceding.vertices needs to be computed. The consequences of the pipeline stall is a significant decrease in the rendering speed.
Thus, what is needed is a method for rendering back-side color as needed without incurring a pipeline stall and the associated loss of efficiency. The required solution should be able to seamlessly handle both the front-side lighting and the back-side lighting as dictated by the geometry of the scene being rendered. In addition, the required solution should be capable of handling both front-side and back-side lighting without incurring an excessive hardware penalty in its implementation. The present invention provides a novel solution to the above requirements.
The present invention is a method and system for efficiently implementing two sided vertex lighting in the hardware of the graphics rendering pipeline. The present invention provides a method for rendering back-side color as needed without incurring a pipeline stall and the associated loss of efficiency. The system the present invention is able to seamlessly handle both the front-side lighting and the back-side lighting as dictated by the geometry of the scene being rendered. In addition, the system the present invention can be implemented without incurring an excessive hardware penalty (e.g., die surface area).
In one embodiment, the present invention is implemented as a system of logic included in a graphics pipeline for performing front-side and back-side vertex lighting of successive vertices in the graphics pipeline of a computer system without incurring pipeline stalls. As successive vertices are received, for each vertex, the system of the present invention computes the dot product terms for a plurality of light sources with respect to the vertex to obtain a magnitude and a sign of the dot product terms, wherein a positive dot product term corresponds to a front-side color and a negative dot product term corresponds to a back-side color. For each of the plurality of light sources, a color value corresponding to the light source for the vertex is computed. The resulting color values are multiplied and accumulated in parallel to obtain a respective front-side vertex color and back-side vertex color. The negative signed color values are multiplied and accumulated to obtain a back-side color. The positive signed vertex colors are multiplied and accumulated to obtain a front-side color. The geometric orientation of the polygon corresponding to the vertex is then determined (e.g., by the geometry subsystem) to ascertain whether the polygon is front facing or back facing. If the corresponding polygon is front facing, the front-side vertex color is output. If the corresponding polygon is back facing, the back-side vertex color is output, thereby allowing front-side and back-side vertex lighting to precede efficiently without pipeline stalling. The correct color is output (e.g., multiplexed out) once the geometry of the polygon corresponding to the vertex is known.
In so doing, only the multiply and accumulate hardware is duplicated, since resulting color values for both the front-side and the back-side are multiplied and accumulated in parallel. Hence, the system of the present invention can be efficiently implemented without incurring excessive die area penalties.